unit uLoginFiremonkey;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants,
  FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
  FMX.Edit, Windows, FMX.Objects, FMX.Media;

type
  TUsuarios = record
    Nombre: String;
    Password: String;
  end;

type
  TFmLogin = class(TForm)
    lblUsuario: TLabel;
    edUsuario: TEdit;
    edContrasena: TEdit;
    lblContrasena: TLabel;
    btnConectar: TButton;
    mpIntro: TMediaPlayer;
    lblVersion: TLabel;
    imgFondo: TImage;
    imgCalavera: TImage;
    imgPlay: TImage;
    imgMute: TImage;
    procedure btnConectarClick(Sender: TObject);
    procedure edContrasenaKeyDown(Sender: TObject; var Key: Word;
      var KeyChar: Char; Shift: TShiftState);
    procedure edUsuarioKeyDown(Sender: TObject; var Key: Word;
      var KeyChar: Char; Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
    procedure tmrMusicLoopTimer(Sender: TObject);
    procedure imgPlayClick(Sender: TObject);
    procedure imgMuteClick(Sender: TObject);
  private
    { Private declarations }
  public
    Usuarios: array [0 .. 2] of TUsuarios;
    { Public declarations }
  end;

var
  FmLogin: TFmLogin;

implementation

{$R *.fmx}

uses uMainFiremonkey;

procedure TFmLogin.btnConectarClick(Sender: TObject);
var
  i: Integer;
begin
  Usuarios[0].Nombre := 'GINES';
  Usuarios[1].Nombre := 'MARIANO';
  Usuarios[2].Nombre := 'MIGUEL';
  Usuarios[0].Password := 'DIGITAL';
  Usuarios[1].Password := 'DIGITAL';
  Usuarios[2].Password := '';

  for i := 0 to 2 do
  Begin
    if (UpperCase(Usuarios[i].Nombre) = UpperCase(edUsuario.Text)) and
      (UpperCase(Usuarios[i].Password) = UpperCase(edContrasena.Text)) then
    Begin
      Application.CreateForm(TFmPrincipal, FmPrincipal);
      FmLogin.Visible := False;
      FmPrincipal.ShowModal;
    End;
  end;
end;

procedure TFmLogin.edContrasenaKeyDown(Sender: TObject; var Key: Word;
  var KeyChar: Char; Shift: TShiftState);
begin
  if Key = vk_Return then
    btnConectarClick(self);
end;

procedure TFmLogin.edUsuarioKeyDown(Sender: TObject; var Key: Word;
  var KeyChar: Char; Shift: TShiftState);
begin
  if Key = vk_Return then
    btnConectarClick(self);
end;

procedure TFmLogin.FormCreate(Sender: TObject);
begin
  ForceDirectories(ExtractFilePath(ParamStr(0)) + 'config\');
  mpIntro.FileName := ExtractFilePath(ParamStr(0)) + 'res\musica.mp3';
  mpIntro.Play;
  mute := False;
end;

procedure TFmLogin.imgMuteClick(Sender: TObject);
begin
  imgPlay.Visible := True;
  imgMute.Visible := False;
  mpIntro.Play;
end;

procedure TFmLogin.imgPlayClick(Sender: TObject);
begin
  imgPlay.Visible := False;
  imgMute.Visible := True;
  mpIntro.Stop;
end;

procedure TFmLogin.tmrMusicLoopTimer(Sender: TObject);
begin
  if (mpIntro.CurrentTime >= mpIntro.Duration) then
  Begin
    mpIntro.Stop;
    mpIntro.Play
  End;
end;

end.
